home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 41.zip / BS1 part 41 / Amiga Plus 1.adf / Programming / sampleevnt.c < prev    next >
C/C++ Source or Header  |  1978-04-08  |  4KB  |  144 lines

  1. /* :ts=8 */
  2. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
  3. /*                                                              */
  4. /*      SampleEvnt.c                                            */
  5. /*                                                              */
  6. /*      Event Handler for AmigaPLUS article about Intuition    */
  7. /*      Written by Michael G. Lehman                            */
  8. /*      of Intuitive Technologies                               */
  9. /*                                                              */
  10. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
  11.  
  12.  
  13. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
  14. /*      Complete Include file for Amiga programs                */
  15. /*      Derived from examples supplied by Commodore Amiga       */
  16. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
  17.  
  18.  
  19. #include <exec/types.h>
  20. #include <exec/nodes.h>
  21. #include <exec/lists.h>
  22. #include <exec/memory.h>
  23. #include <exec/ports.h>
  24. #include <exec/tasks.h>
  25. #include <exec/libraries.h>
  26. #include <exec/devices.h>
  27. #include <exec/io.h>
  28. #include <exec/devices.h>
  29.  
  30. #include <libraries/dos.h>
  31.  
  32. #include <graphics/gfx.h> /* ALWAYS INCLUDE GFX.H before other includes */
  33. #include <graphics/display.h>
  34. #include <graphics/clip.h>
  35. #include <graphics/rastport.h>
  36. #include <graphics/gfxbase.h>
  37. #include <graphics/text.h>
  38. #include <graphics/regions.h>
  39. #include <graphics/copper.h>
  40. #include <graphics/gels.h>
  41.  
  42. #include <devices/inputevent.h>
  43. #include <devices/gameport.h>
  44. #include <devices/console.h>
  45. #include <devices/keymap.h>
  46.  
  47. #include <intuition/intuition.h>
  48.  
  49. struct XMenuItem                /* our extended menu structure */
  50. {
  51.         struct MenuItem *NextItem;
  52.         SHORT LeftEdge, TopEdge;
  53.         SHORT Width, Height;
  54.         USHORT Flags;
  55.         LONG MutualExclude;
  56.         APTR ItemFill;
  57.         APTR SelectFill;
  58.         BYTE Command;
  59.         struct MenuItem *SubItem;
  60.         USHORT NextSelect;
  61.         int (*ItemHndlr)();     /* all above is standard and we add this */
  62. };
  63.  
  64. extern UBYTE * AllocMem();
  65.  
  66. #define SECONDS io_Actual
  67. #define MICROSECONDS io_Length
  68.  
  69. #ifndef max
  70. #define max(a,b) ((a) > (b) ? (a) : (b))
  71. #endif
  72.  
  73. #define IEQUALIFIER_MBUTTON IEQUALIFIER_LEFTBUTTON
  74.  
  75. #define PUBCLEAR MEMF_PUBLIC | MEMF_CLEAR
  76. SHORT textmode;
  77.  
  78. char *Address;          /*general purpose address variable */
  79.  
  80. extern struct RastPort *rp;
  81.  
  82. extern SHORT class;
  83.  
  84. SHORT last_class = -1;
  85. SHORT save_class;
  86. extern SHORT code;
  87. extern USHORT mousex,mousey;
  88. extern SHORT qualifier;
  89. extern struct Window *window;
  90. extern SHORT mode;
  91. SHORT submode;
  92.  
  93. SHORT gadgetid;
  94. LONG quitcode;          /* set by the QUIT menu item handler */
  95.  
  96. SHORT prevMenu = -1;
  97. long (*prevMenuHandler)() = NULL;
  98.  
  99. NoEvent()
  100. {
  101.   last_class = save_class;
  102.   code = -1;
  103.   class = -1;
  104.   qualifier = -1;
  105. }
  106.  
  107.  
  108. HandleEvent()
  109. {
  110.  
  111.   struct RastPort *rp;
  112.   struct IntuiMessage *message;
  113.   extern struct MenuItem *ItemAddress();
  114.  
  115.   long save_code;
  116.  
  117.   quitcode = FALSE;
  118.   switch(class)
  119.   {
  120.  
  121.   case MENUPICK:
  122.  
  123. more_menu_items:
  124.  
  125.     if (MENUNUM(code) != NOMENU && ITEMNUM(code) != NOITEM)
  126.     {
  127.       Address = ItemAddress(window -> MenuStrip,SHIFTMENU(MENUNUM(code)) |                                                  SHIFTITEM(ITEMNUM(code)));
  128.       submode = SUBNUM(code);
  129.       save_code = code;
  130.       (*((struct XMenuItem *)Address)-> ItemHndlr)(NULL);
  131.       code = save_code;
  132.       Address = ItemAddress(window -> MenuStrip,code);
  133.       if (Address && (code=Address -> NextSelect) != MENUNULL &&
  134.           code != save_code)
  135.        goto more_menu_items;
  136.     }
  137.     NoEvent();
  138.     break;
  139.  
  140.   }
  141.  
  142.   return(quitcode);
  143. }
  144.